<?php

/**
 * Flickr Photosets - Photosets Page
 * Displays a list of the user's photosets.
 * 
 * @author Brad Dougherty <bdougherty@gmail.com>
 * @version 2.0
 * @date 9/18/07
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License 3.0
 * @since File available since Release 1.0
 */

/*
Require the function library
This will include all other necessary files
*/
require_once 'lib.php';

/*
Initialize Flickr Photosets and Flickr
*/
$fp = new FlickrPhotosetsCanvas();

// If the user has disabled photosets
if (!$fp->config['enable_gallery_photosets']) {
	$fp->error(FlickrPhotosetsErrors::$photosets_disabled);
}

// Get the photosets and count
$photosets = $fp->flickr->photosets_getList($fp->nsid);
$photoset_count = count($photosets['photoset']);

// Slice the array into the sets that will be displayed on this page only
$photosets['photoset'] = array_slice($photosets['photoset'], (($fp->page - 1) * $fp->sets_per_page), $fp->sets_per_page);

// Calculate the number of pages we will have
$page_count = ceil($photoset_count / $fp->sets_per_page);

?>

<fb:title><?=$fp->get_name(true)?> Photosets</fb:title>

<div class="albums">

	<?=$fp->print_media_header()?>
			
	<div style="margin-top:20px;"> </div>

	<?=$fp->echo_tabs('photosets')?>
	
	<?php if ($photoset_count < 1) {
		$fp->error(FlickrPhotosetsErrors::$no_photosets);
	} else { ?>
		
		<div class="bar clearfix summary_bar">
			<div class="summary">
				<h4>
					<?=$photoset_count?> Photosets
					<span class="pipe">|</span>
					<a href="<?=$fp->flickr->urls_getUserPhotos($fp->nsid)?>sets/">View Sets on Flickr</a>
				</h4>
			</div>
			<?php $fp->pager($page_count); ?>
		</div>

		<div class="panel clearfix">
			<div class="results">

				<?php // Loop through each set
				foreach($photosets['photoset'] as $photoset) { ?>

					<?php $photo = $fp->flickr->photos_getInfo($photoset['primary']); ?>

					<div class="album2 clearfix">
						<div class="image">
							<a href="<?=$fp->app_url?>/photos/<?=$fp->uid?>/sets/<?=$photoset['id']?>/">
								<img src="<?=$fp->flickr->buildPhotoUrl($photo, "small")?>" width="180" alt="<?=$photoset['title']?>" title="<?=$photoset['title']?>" />
							</a>
						</div>

						<div class="info">
							<h2><a href="<?=$fp->app_url?>/photos/<?=$fp->uid?>/sets/<?=$photoset['id']?>/"><?=$photoset['title']?></a></h2>

							<span class="count">
								<?php
								// Fudge the numbers a little bit
								if (($fp->config['privacy_filter'] == $fp->privacy_filter['public']) or ($fp->config['privacy_filter'] == $fp->privacy_filter['private'])) {
									echo $photoset['photos'].' photos';
								}
								else {
									echo 'About '.$fp->round_to_nearest($photoset['photos']).' photos';
								}
								?>
							</span>

							<p><?=$photoset['description']?></p>

							<p class="date">
								<div class="date"></div>
							</p>

							<p>
								<a href="<?=$fp->app_url?>/photos/<?=$fp->uid?>/sets/<?=$photoset['id']?>/">View Set</a>
								<span class="pipe">|</span>
								<a href="<?=$fp->flickr->urls_getUserPhotos($fp->nsid)?>sets/<?=$photoset['id']?>/">View Set on Flickr</a>
							</p>

							<p>
								<fb:share-button class="meta">
									<meta name="title" content="Flickr Photoset: <?=$photoset['title']?>" />
									<meta name="description" content="<?=$photoset['description']?>" />
									<link rel="image_src" href="<?=$fp->flickr->buildPhotoUrl($photo, 'thumbnail')?>" />
									<link rel="target_url" href="<?=$fp->app_url?>/photos/<?=$fp->uid?>/sets/<?=$photoset['id']?>/" />
								</fb:share-button>
							</p>
						</div>

					</div>

				<?php } ?>

			</div>

		</div>
		
	<?php } ?>
	
	<div class="bar clearfix footer_bar">
		<?php $fp->pager($page_count); ?>
	</div>
	
</div>

<?=$fp->echo_footer()?>